package com.example.juc.vo;

import java.util.concurrent.atomic.AtomicInteger;

// 不保证原子性
public class VolitileDemo {

    private volatile static AtomicInteger num = new AtomicInteger();

    private static void add(){
        num.getAndIncrement();
    }

    public static void main(String[] args) {
        for (int i =0 ;i<19;i++){
            new Thread(()->{
                for (int j = 0 ;j<10000;j++){
                    add();
                }
            }).start();
        }
        while (Thread.activeCount()>2){
            Thread.yield();
        }
        System.out.println(Thread.currentThread().getName()+"->"+num);
    }
}
